
/*
OV7670 Camera Module / SCCB (Serial Camera Control Bus) Interface
Copyright (C) 2012 Craig Dawson, Aaron Mohtar, Craig Peacock

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#define OV7670_I2C_ADDR         0x42

#define OV7670_GAIN             0x00
#define OV7670_BLUE             0x01
#define OV7670_RED              0x02
#define OV7670_VREF             0x03
#define OV7670_PID              0x0A
#define OV7670_VER              0x0B
#define OV7670_COM3             0x0C
#define OV7670_COM4             0x0D
#define OV7670_COM5             0x0E
#define OV7670_COM6             0x0F
#define OV7670_CLKRC            0x11
#define OV7670_COM7             0x12
#define OV7670_COM10            0x15
#define OV7670_HSTART           0x17
#define OV7670_HSTOP            0x18
#define OV7670_VSTART           0x19
#define OV7670_VSTOP            0x1A
#define OV7670_MVFP             0x1E
#define OV7670_HREF             0x32
#define OV7670_TSLB             0x3A
#define OV7670_COM11            0x3B
#define OV7670_COM14            0x3E
#define OV7670_COM15            0x40
#define OV7670_RGB444           0x8C
#define OV7670_SCALING_XSC      0x70
#define OV7670_SCALING_YSC      0x71
#define OV7670_SCALING_DCWCTR   0x72
#define OV7670_SCALING_PCLK_DIV 0x73

#define OV7670_FIFO_OEN         LATBbits.LATB10
#define OV7670_FIFO_OEN_TRIS    TRISBbits.TRISB10

#define OV7670_FIFO_RCLK        LATBbits.LATB11
#define OV7670_FIFO_RCLK_TRIS   TRISBbits.TRISB11

#define OV7670_FIFO_RRST        LATBbits.LATB12
#define OV7670_FIFO_RRST_TRIS   TRISBbits.TRISB12

void ov7670Init(void);
void ov7670DisplayFrame(void);
void sccbInit(void);
unsigned char sccbWriteCommand(unsigned char address, unsigned char command, unsigned char data);
unsigned char sccbReadCommand(unsigned char address, unsigned char command);
